package com.xnyzc.lhy.common.util;

import org.apache.commons.lang3.StringUtils;

/**
 * @Author: huxuekuo
 * @Date: 2019-08-12 20:16
 * @Description:
 */
public class StringUtil extends StringUtils {

    /**
     * 判断是否是带小数的字符串
     *
     * @param str
     * @return
     */
    public static double isDouble(String str) {
        if (str.matches("-?[0-9]+.*[0-9]*")) {
            return Double.valueOf(str);
        } else {
            return 0.0;
        }
    }

    public static String isEmpty(String one, String two) {
        if (CheckUtil.strIsEmpty(one) && CheckUtil.strIsEmpty(two)) {
            return "";
        }
        String str = "";
        if (!CheckUtil.strIsEmpty(one)) {
            str = one;
        }

        if (!CheckUtil.strIsEmpty(two)) {
            str = two;
        }
        return str;
    }

    /**
     * 截取手机尾号,如果位数为空默认4位
     *
     * @param phone
     * @param numberBit
     * @return
     */
    public static String getPhoneTailNumber(String phone, Integer numberBit) {
        if (CheckUtil.objIsEmpty(numberBit)) {
            numberBit = 4;
        }
        return phone.substring(phone.length() - numberBit, phone.length());
    }

    /**
     * 判断字符串是否为null,如果为null返回空字符串
     * @param str
     * @return
     */
    public static String isNullReturnEmpty(String str) {
        if (CheckUtil.strIsEmpty(str)) {
            return "";
        }
        return str;
    }

}
